﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using SimpleFS.Storage.Ftp;

namespace SimpleFS.Specs.Providers.Ftp
{
    [TestFixture]
    public class FileTest
    {
        protected string url;

        protected string user;

        protected string password;

        protected File file;

        [SetUp]
        public void SetUp()
        {
        }

        [TearDown]
        public void TearDown()
        {
            this.file.Close();
        }

        [Test]
        public void TestRead()
        {
            url = "ftp://localhost/AJ12_EN.pdf";
            user = "Sam";
            password = "";

            this.file = new File(url, user, password);
            System.IO.Stream stream = this.file.Read();

            Assert.IsNotNull(stream);
        }

        [Test]
        public void TestWrite()
        {
            string fileName = "../../Resources/Hello.txt";
            url = "ftp://localhost/Hello.txt";
            user = "Sam";
            password = "";

            this.file = new File(url, user, password);

            System.IO.FileStream stream = System.IO.File.Open(
                fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            this.file.Write(stream);

            Assert.IsTrue(this.file.Exists());
        }

        [Test]
        public void TestExist()
        {
            url = "ftp://localhost/AJ12_EN.pdf";
            user = "Sam";
            password = "";

            this.file = new File(url, user, password);

            Assert.IsTrue(this.file.Exists());

            url = "ftp://localhost/not-existed.pdf";
            user = "Sam";
            password = "";

            this.file = new File(url, user, password);

            Assert.IsFalse(this.file.Exists());
        }
    }
}
